package com.huanshi.module.oms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huanshi.common.CommonResult;
import com.huanshi.entity.OmsOrder;
import com.huanshi.module.oms.param.OrderParam;
import com.huanshi.service.OmsOrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 幻世
 * @since 2023-10-12
 */
@RestController
@RequestMapping("/api/oms/order")
public class OmsOrderController {

    @Resource
    private OmsOrderService orderService;

    // 新增或者更新
    @PostMapping("/update")
    public CommonResult update(@RequestBody OmsOrder order) {return CommonResult.success(orderService.updateById(order ));
    }


    @PostMapping("/create")
    public CommonResult create(@RequestBody OrderParam order) {
        return CommonResult.success(orderService.createOrder(order));
    }

    @DeleteMapping("/{id}")
    public CommonResult delete(@PathVariable Integer id) {
        return CommonResult.success(orderService.removeById(id));
    }

    @PostMapping("/del/batch")
    public CommonResult deleteBatch(@RequestBody List<Integer> ids) {
        return CommonResult.success(orderService.removeByIds(ids));
    }


    @GetMapping
    public CommonResult findOne(@RequestParam String orderSn) {
        return CommonResult.success(orderService.getByOrderSn(orderSn));
    }

    @GetMapping("/page")
    public CommonResult findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize,
                                 @RequestParam(defaultValue = "") Integer status) {

        return CommonResult.success(orderService.findPage(new Page<>(pageNum, pageSize), status));
    }

}

